Chapter 5 LAGOS Analysis
5.1 Loading in data
5.1.1 First download and then specifically grab the locus (or site lat longs)
# #Lagos download script
LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())
#Load in lagos
lagos <- lagosne_load()
#Grab the lake centroid info
lake_centers <- lagos$locus5.1.2 Convert to spatial data
#Look at the column names
#names(lake_centers)
#Look at the structure
#str(lake_centers)
#View the full dataset
#View(lake_centers %>% slice(1:100))
spatial_lakes <- st_as_sf(lake_centers,coords=c('nhd_long','nhd_lat'),
crs=4326) %>%
st_transform(2163)
#Subset for plotting
subset_spatial <- spatial_lakes %>%
slice(1:100)
subset_baser <- spatial_lakes[1:100,]
#Dynamic mapviewer
#mapview(subset_spatial)5.1.3 Subset to only Minnesota
states <- us_states()
#Plot all the states to check if they loaded
#mapview(states)
minnesota <- states %>%
filter(name == 'Minnesota') %>%
st_transform(2163)
#Subset lakes based on spatial position
minnesota_lakes <- spatial_lakes[minnesota,]
#Plotting the first 1000 lakes
minnesota_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')5.2 In-Class work
5.2.1 1) Show a map outline of Iowa and Illinois (similar to Minnesota map upstream)
Iowa_Illinois <- states %>%
filter(name %in% c('Iowa', 'Illinois')) %>%
st_transform(2163)
mapview(Iowa_Illinois)5.2.2 2) Subset LAGOS data to these sites, how many sites are in Illinois and Iowa
combined? How does this compare to Minnesota?
A: Iowa and Illinois have 16,466 sites, fewer than Minnesota, which has 29,038.
Iowa_Illinois_lakes <- spatial_lakes[Iowa_Illinois,]
nrow(Iowa_Illinois_lakes)## [1] 16466
nrow(minnesota_lakes)## [1] 29038
5.2.3 3) What is the distribution of lake size in Iowa vs. Minnesota?
- Here I want to see a histogram plot with lake size on x-axis and frequency on y axis (check out geom_histogram)
A: As can be seen in the histogram below, both Iowa and Minnesota show a larger distribution of numbers with smaller lakes. However, since the number of lakes in Minnesota is much higher than in Iowa, it can be seen that the distribution of lakes is more diverse and wider.
# Make Iowa's lake size data not Iowa_Illinois, using lake area
Iowa <- states %>%
filter(name=='Iowa') %>%
st_transform(2163)
Iowa_lakes <- spatial_lakes[Iowa,]
Iowa_lakes_size <- data.frame(Iowa_lakes$lake_area_ha) %>%
rename(Lake_Size=1) %>%
mutate(State='Iowa')
# Make Minnesota's lakes size data in similar way
minnesota_lakes_size <- data.frame(minnesota_lakes$lake_area_ha) %>%
rename(Lake_Size=1) %>%
mutate(State='Minnesota')
# Bind two data frames to make a plot
Compare_lake_size <- rbind(Iowa_lakes_size, minnesota_lakes_size)
# Make a histogram plot
p<- ggplot(Compare_lake_size, aes(x=Lake_Size, fill=State)) +
xlim(1,200) +
xlab('Lake Size(ha)') +
geom_histogram(bins = 100, alpha=0.5) +
theme_few() +
theme(legend.position=c(0.8,0.7))
p+scale_fill_manual(values = c("Red", "Green"))
Figure 5.1: Compare lake size between Iowa and Minnesota
5.2.4 4) Make an interactive plot of lakes in Iowa and Illinois and color them by lake area in hectares
Iowa_Illinois_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')5.2.5 5) What other data sources might we use to understand how reservoirs and natural lakes vary in size in these three states?
A: For comparing lake size in another way, you can use perimeter length of lakes instead of lake area. The map below shows the variation of lake size using perimeter of lakes in three states.
Compare_lake_length <- rbind(minnesota_lakes, Iowa_Illinois_lakes)
Compare_lake_length %>%
arrange(-lake_perim_meters) %>%
slice(1:1000) %>%
mapview(., zcol='lake_perim_meters')